<?php


class EventsResultSet
{
	private $events=array();
	private $from; // DateTime object
	private $to; // DateTime object
	
	public function __construct()
	{
//		echo 'EventsResultSet::__construct()<br>';
		$this->from = new DateTime("2000-01-01"); // DateTime object
		$this->to = new DateTime("2022-12-31"); // DateTime object
	}
	
	public function setFrom($from){$this->from=$from;}
	public function setTo($to){$this->to=$to;}
	
	
	public function getEvents()
	{
//		echo 'EventsResultSet::getEvents()<br>';
		$database=$GLOBALS['DATABASE']->Recopy();
		
		$sql = "SELECT Ev.EventID,Inv.EventInvolveeNameID FROM Events as Ev ";
		$sql .= "INNER JOIN EventInvolvees AS Inv ON Ev.EventID = Inv.EventID ";
		$sql .= "WHERE Ev.Start >= '".$this->from->format("Y-m-d")."' ";
		$sql .= "AND Ev.Start<='".$this->to->format("Y-m-d")."' ";
		$sql .= "AND Ev.DeletedBy = 0 ";
		$sql .= "AND Inv.EventInvolveeNameID = 14 "; // music required = 14
		$sql .= "ORDER BY Ev.Start,Ev.EventID";

	
		
//		echo $sql.'<br>';
		$database->executeSQL($sql);
		while($row=$database->getRow())
		{
			$event=new Event($row['EventID']);
//			echo $row['Title'];
			array_push($this->events,$event);
		}
		return $this->events;
	}
}
